﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace text.StrProblem
{
    public class _17
    {
        private String[] letterMap = {
                "",    //0
                "",     //1
                "abc",  //2
                "def",  //3
                "ghi",  //4
                "jkl",  //5
                "mno",  //6
                "pqrs", //7
                "tuv",  //8
                "wxyz"  //9
        };
        public List<String> res;

        public IList<string> LetterCombinations(string digits)
        {
            res = new List<string>();
            findCombination(digits,0,"");
            return res;
        }
        public void findCombination(string digits, int index, string s)
        {
            if (digits=="")
            {
                return;
            }
            if (s.Length==digits.Length)
            {
                res.Add(s);
                return;
            }
            char c = digits[index];
            string letter = letterMap[c - '0'];
            for (int i = 0; i < letter.Length; i++)
            {
                findCombination(digits, index + 1,s+ letter[i]);
            }
            return;
        }
    }
}
